﻿using System;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace FitAutomation
{
	[DataContract]
	public class ProcessIdentifier
	{

		[DataMember]
		public int ProcessId { get; set; }

		[DataMember]
		public Identifier Id { get; set; }

		public ProcessIdentifier(Process process, Identifier id)
		{
			ProcessId = process.Id;
			Id = id;
		}

		public override string ToString()
		{
			if (Id == null)
			{
				return "P: Id == null";
			}
			return "P" + ProcessId + ": " + Id.ToString();
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != GetType()) return false;
			return Equals((ProcessIdentifier)obj);
		}

		public bool Equals(ProcessIdentifier other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return other.ProcessId == ProcessId && Equals(other.Id, Id);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				return (ProcessId*397) ^ (Id != null ? Id.GetHashCode() : 0);
			}
		}
	}
}